Socket
Socket
Sign inDemoInstall

@google-cloud/storage

Package Overview
Dependencies
98
Maintainers
1
Versions
178
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @google-cloud/storage

Cloud Storage Client Library for Node.js


Version published
Weekly downloads
2.6M
decreased by-18.39%
Maintainers
1
Install size
7.93 MB
Created
Weekly downloads
 

Package description

What is @google-cloud/storage?

The @google-cloud/storage npm package is a client library for using Google Cloud Storage, which is a service for storing and accessing data on Google's infrastructure. The package allows Node.js developers to interact with Google Cloud Storage in a server-side application.

What are @google-cloud/storage's main functionalities?

Uploading files

This feature allows users to upload files to a Google Cloud Storage bucket. The code sample demonstrates how to upload a local file to a specified bucket.

const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
async function uploadFile() {
  await storage.bucket('my-bucket').upload('local-file-path', {
    destination: 'destination-file-path',
  });
  console.log('File uploaded.');
}
uploadFile().catch(console.error);

Downloading files

This feature enables users to download files from a Google Cloud Storage bucket. The code sample shows how to download a file from a bucket to the local file system.

const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
async function downloadFile() {
  const options = {
    destination: 'local-file-path',
  };
  await storage.bucket('my-bucket').file('remote-file-path').download(options);
  console.log('File downloaded.');
}
downloadFile().catch(console.error);

Listing files

This feature provides the ability to list all files in a Google Cloud Storage bucket. The code sample lists the names of all files in a specified bucket.

const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
async function listFiles() {
  const [files] = await storage.bucket('my-bucket').getFiles();
  files.forEach(file => console.log(file.name));
}
listFiles().catch(console.error);

Deleting files

This feature allows users to delete files from a Google Cloud Storage bucket. The code sample demonstrates how to delete a specific file from a bucket.

const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
async function deleteFile() {
  await storage.bucket('my-bucket').file('file-to-delete').delete();
  console.log('File deleted.');
}
deleteFile().catch(console.error);

Managing buckets

This feature enables users to manage buckets, including creating and deleting buckets. The code sample shows how to create a new bucket in Google Cloud Storage.

const { Storage } = require('@google-cloud/storage');
const storage = new Storage();
async function createBucket() {
  await storage.createBucket('new-bucket');
  console.log('Bucket created.');
}
createBucket().catch(console.error);

Other packages similar to @google-cloud/storage

Changelog

Source

v2.5.0

04-04-2019 12:27 PDT

This release brings an option to file#getSignedURL to create a version 4 Signed URL.

file.getSignedUrl({
  version: 'v4', // optional, defaults to v2 (existing version)
  action: 'read',
  expires: FUTURE_DATE,
})

New Features

  • feat: introduce v4 signed url (#637)

Dependencies

  • chore(deps): update dependency @types/node to v11.13.0 (#662)
  • chore(deps): update dependency @types/tmp to v0.1.0
  • chore(deps): upgrade to newest version of @google-cloud/common (#657)
  • chore(deps): update dependency typescript to ~3.4.0
  • chore(deps): update dependency tmp to ^0.1.0 (#641)

Documentation

  • docs: regenerate the samples/README.md (#649)
  • docs: slight difference in how nightly synthtool run generated README (#650)
  • docs: new synthtool generated README (#645)
  • docs(samples): refactor the quickstart to match the new rubric (#647)
  • docs: update README format
  • docs: add requires_billing, retire .cloud-repo-tools.json (#644)
  • docs: add additional api_id field (#640)
  • docs: document destination option (#633)
  • docs: clarify in docs, the meaning of ASIA and coldline (#632)
  • docs: add a .repo-metadata.json (#639)

Internal / Testing Changes

  • test(v2-sign): add multi-valued headers system-test (#646)
  • refactor: replace once with onetime (#660)
  • fix: do not download cached files (#643)
  • chore: publish to npm using wombat (#634)
  • build: use per-repo npm publish token (#630)

Readme

Source

Google Cloud Platform logo

Google Cloud Storage: Node.js Client

release level npm version codecov

Node.js idiomatic client for Cloud Storage.

Cloud Storage allows world-wide storage and retrieval of any amount of data at any time. You can use Google Cloud Storage for a range of scenarios including serving website content, storing data for archival and disaster recovery, or distributing large data objects to users via direct download.

Read more about the client libraries for Cloud APIs, including the older Google APIs Client Libraries, in Client Libraries Explained.

Table of contents:

Quickstart

Before you begin

  1. Select or create a Cloud Platform project.
  2. Enable billing for your project.
  3. Enable the Google Cloud Storage API.
  4. Set up authentication with a service account so you can access the API from your local workstation.

Installing the client library

npm install @google-cloud/storage

Using the client library

  // Imports the Google Cloud client library
  const {Storage} = require('@google-cloud/storage');

  // Creates a client
  const storage = new Storage();

  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const bucketName = 'bucket-name';

  async function createBucket() {
    // Creates the new bucket
    await storage.createBucket(bucketName);
    console.log(`Bucket ${bucketName} created.`);
  }

  createBucket();

Samples

Samples are in the samples/ directory. The samples' README.md has instructions for running the samples.

SampleSource CodeTry it
Aclsource codeOpen in Cloud Shell
Bucket Locksource codeOpen in Cloud Shell
Bucketssource codeOpen in Cloud Shell
Encryptionsource codeOpen in Cloud Shell
Filessource codeOpen in Cloud Shell
Iamsource codeOpen in Cloud Shell
Notificationssource codeOpen in Cloud Shell
Quickstartsource codeOpen in Cloud Shell
Requester Payssource codeOpen in Cloud Shell

The Google Cloud Storage Node.js Client API Reference documentation also contains samples.

Versioning

This library follows Semantic Versioning.

This library is considered to be General Availability (GA). This means it is stable; the code surface will not change in backwards-incompatible ways unless absolutely necessary (e.g. because of critical security issues) or with an extensive deprecation period. Issues and requests against GA libraries are addressed with the highest priority.

More Information: Google Cloud Platform Launch Stages

Contributing

Contributions welcome! See the Contributing Guide.

License

Apache Version 2.0

See LICENSE

Keywords

FAQs

Last updated on 04 Apr 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc